/**
 *    y
 *    ↑
 *    o → x
 *  ↙z
 * 
 *     v5----- v8
 *   /|      /|
 *  v1------v4|
 *  | |     | |
 *  | |v6---|-|v7
 *  |/      |/
 *  v2------v3
 */

let v1 = [-0.5, 0.5, 0.5]
let v2 = [-0.5, -0.5, 0.5]
let v3 = [0.5, -0.5, 0.5]
let v4 = [0.5, 0.5, 0.5]
let v5 = [-0.5, 0.5, -0.5]
let v6 = [-0.5, -0.5, -0.5]
let v7 = [0.5, -0.5, -0.5]
let v8 = [0.5, 0.5, -0.5]

let positions = [
    ...v1, ...v2, ...v3, ...v4, // 前面
    ...v5, ...v6, ...v7, ...v8, // 后面
    ...v5, ...v6, ...v2, ...v1, // 左面
    ...v4, ...v3, ...v7, ...v8, // 右面
    ...v5, ...v1, ...v4, ...v8, // 上面
    ...v6, ...v2, ...v3, ...v7, // 下面
]

let c1 = [1.0, 0.0, 0.0]
let c2 = [0.0, 1.0, 0.0]
let c3 = [0.0, 0.0, 1.0]
let c4 = [0.0, 1.0, 1.0]
let c5 = [1.0, 0.0, 1.0]
let c6 = [1.0, 1.0, 0.0]

let colors = [
    ...c1, ...c1, ...c1, ...c1, //前面
    ...c2, ...c2, ...c2, ...c2, //后面
    ...c3, ...c3, ...c3, ...c3, //左面  
    ...c4, ...c4, ...c4, ...c4,//右面
    ...c5, ...c5, ...c5, ...c5, //上面
    ...c6, ...c6, ...c6, ...c6, //下面
]

let n1 = [0.0, 0.0, 1.0]
let n2 = [0.0, 0.0, -1.0]
let n3 = [-1.0, 0.0, 0.0]
let n4 = [1.0, 0.0, 0.0]
let n5 = [0.0, 1.0, 0.0]
let n6 = [0.0, -1.0, 0.0]
let normals = [
    ...n1, ...n1, ...n1, ...n1, //前面
    ...n2, ...n2, ...n2, ...n2, //后面
    ...n3, ...n3, ...n3, ...n3, //左面  
    ...n4, ...n4, ...n4, ...n4,//右面
    ...n5, ...n5, ...n5, ...n5, //上面
    ...n6, ...n6, ...n6, ...n6, //下面
]



    
export function initVertexBuffers(gl) {
    let FSIZE = positions.BYTES_PER_ELEMENT // Float32 Size = 4

    let positionsBuffer = gl.createBuffer()
    gl.bindBuffer(gl.ARRAY_BUFFER, positionsBuffer)
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW)
    let a_position = gl.getAttribLocation(gl.program, 'a_position')
    gl.vertexAttribPointer(a_position, 3, gl.FLOAT, false, FSIZE * 3, 0)
    gl.enableVertexAttribArray(a_position)

    let colorsBuffer = gl.createBuffer()
    gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer)
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW)
    let a_color = gl.getAttribLocation(gl.program, 'a_color')
    gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, FSIZE * 3, 0)
    gl.enableVertexAttribArray(a_color)

        
    let normalsBuffer = gl.createBuffer()
    gl.bindBuffer(gl.ARRAY_BUFFER, normalsBuffer)
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normals), gl.STATIC_DRAW)
    let a_normal = gl.getAttribLocation(gl.program, 'a_normal')
    gl.vertexAttribPointer(a_normal, 3, gl.FLOAT, false, FSIZE * 3, 0)
    gl.enableVertexAttribArray(a_normal)

}